<?php 
include("common/conn.php"); 
if($_SESSION['shopid']=="") {
  echo "<script>window.location.href='login.php';</script>";
} 
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>e网生活管理后台</title>
<script type="text/javascript" src="js/jquery.min.js"></script>
<link href="css/styles.css" rel="stylesheet" type="text/css" />
<link href="css/style2.css" rel="stylesheet" type="text/css" />
<script type="text/JavaScript">
    <!--
function MM_jumpMenu(targ,selObj,restore){ //v3.0
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}
//-->
</script>
</head>

<body>

  <!--header-->
<?php 
include("common/header.php");

if($_GET['del']=="ok"){
  $area = array(); 
  $area= $_POST['checkbox'];

  foreach ($area as $k=>$v){
    $srat1=mysql_query("DELETE FROM goods where goodsid='".$v."'");
  }
  if ($_GET['shopid']!='') {
    echo "<script>alert('删除成功');window.location.href='goods2.php?shopid=".$_GET['shopid']."'</script>";
  }else{
    echo "<script>alert('删除成功');window.location.href='goods2.php'</script>";
  }
  

}

?>
  <!--header end-->


  <!-- staqrt subnav -->
  <div id="sub_nav">
    <div id="subnav_wrap" class="container_12">
      <div id="subnav" class=" grid_12">
        <ul>
          <li>
              <a href="goods2.php" class="sub_nav_active" >商品管理</a>
          </li>
        </ul>
      </div>
    </div>

  </div>
  <div class="container_12">
    <form action="?id=<?php echo $_REQUEST[id]; ?>" method="post">
        <input type="button" class="submit" value="新增商品" onclick="add();">
    </form>
    </div>
    <!-- end sub_nav -->
    <form action="?del=ok" method="post">
      <!-- EVERYTING BELOW IS THE MAIN CONTENT -->


      <table width="100%" border="0" cellpadding="0" cellspacing="0">
        <tr>
          <th width="2%" scope="col"><input type="checkbox" name="checkbox" id="checkbox" class="checkall" />
          <th width="8%" scope="col">地区</th>
          <th width="8%" scope="col">商家</th>
          <th width="10%" scope="col">图	</th>
          <th width="10%" scope="col">标题</th>
          <th width="10%" scope="col">分类</th>
          <th width="10%" scope="col">出售价格</th>
          <th width="5%" scope="col">销量</th>
          <th width="15%" scope="col">操作</th>
        </tr>

<?php 
mysql_query('SET NAMES UTF8');
if($_GET['page'] == null) {
  $page = 0;
} else {
  $page = $_GET['page'];
}
$sql  = "SELECT a.`goodsid`, a.`title`, a.`price`, a.`xiaoliang`, a.`images`, b.`city`, b.`name` AS bname, c.`name` AS cname, d.`name`  AS dname, e.`name` AS ename FROM goods AS a "; 
$sql .=  "LEFT JOIN shop AS b "; 
$sql .=   "ON a.`shopid` = b.`shopid` "; 
$sql .= "LEFT JOIN categroy AS c ";
$sql .= "ON b.`leimu` = c.`cateid` "; 
$sql .= "LEFT JOIN zifenlei AS d "; 
$sql .= "ON a.`zixilie` = d.`id` ";
$sql .= "LEFT JOIN city AS e ";
$sql .= "ON b.`city` = e.`id` ";
$sql .= "WHERE a.`shopid` = " . $_SESSION['shopid'] . " LIMIT " . $page . ",10";

$res = mysql_query($sql);
while ($goods = mysql_fetch_array($res)) {
  $img = $goods[images];
  $de = array();
  $de = explode("," ,$img);
  $images = $de[0];

?>
  <tr>
    <td scope="col">
        <input type="checkbox" name="checkbox[]" id="checkbox"  value="<?php echo $goods[goodsid];?>"/>
    </td>
    <td scope="col">
        <?php echo $goods[ename];?>
        <?php echo $goods[quyu];?>
    </td>
    <td scope="col">
        <?php echo $goods[bname];?>
    </td>
    <td scope="col">
        <img src="http://<?php echo $_SERVER['SERVER_NAME'] . '/' . $images;?>" height="50" width="50"/>
    </td>
    <td scope="col">
        <?php echo $goods[title];?>
    </td>
    <td scope="col">
        <?php echo $goods[cname];?>-<?php echo $goods[dname];?>
    </td>
    <td scope="col">
        <?php echo $goods[price];?>
    </td>
    <td scope="col">
        <?php echo $goods[xiaoliang];?>
    </td>
    <td scope="col">
    <div class="youse">
        <a href="addgoods.php?gid=<?php echo $goods[goodsid];?>&shopid=<?php echo $_SESSION[shopid]; ?>">编辑商品</a>
    </div>
    <div class="youse2">
        <a href="addgoodsimg.php?id=<?php echo $goods[goodsid];?>">商品图库</a>
    </div>
    </td>
  </tr>
<?php } ?>
</table>
<input  type="submit" value="删除选中" />
</div>
</form>
  <ul id="pagination">
      <li><a href="?page=<?php echo 0 ?>">首页</a></li>
      <?php if(!$page < 1) {?>
      <li><a href="?page=<?php echo $page-1 ?>">上一页</a></li>
      <?php } ?>
      <li><a href="?page=<?php echo $page+1 ?>">下一页</a></li>
  </ul>
<input type="hidden" id="id" value="<?php echo $_REQUEST[id]; ?>">
<input type="hidden" id="shopid" value="<?php echo $_SESSION[shopid]; ?>">
</body>
<script type="text/javascript">
  var id = $('#id').val();
  var shopid = $('#shopid').val();

  function add(){
    window.location.href="addgoods.php?shopid="+shopid+"&id="+id;
  }
</script>
</html>
